package jzqb.dao.impl;

import cnki.tpi.kbatis.sqlsession.SqlSession;
import cnki.tpi.kbatis.utils.DataSourceUtil;
import jzqb.bo.QBFWAuditBo;
import jzqb.bo.QBFWBo;
import jzqb.dao.IQBFWDao;
import jzqb.po.AdminDepartmentPo;
import jzqb.po.AdminPermissionGroupPo;
import jzqb.po.LCPo;
import jzqb.po.QBFWPo;
import jzqb.vo.QBFWVo;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Description:
 *
 * @author BaiGe
 * @date: 2021/6/21 17:02
 * @Version 1.0
 */
@Repository
public class QBFWDaoImpl implements IQBFWDao {


    @Override
    public Boolean insertQBFW(QBFWPo qbfwPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.insertQBFW";
        return sqlSession.executeInsert(statementId, qbfwPo);
    }

    @Override
    public AdminDepartmentPo findDeptLeader(String deptId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findDeptLeader";
        AdminDepartmentPo adminDepartmentPo = sqlSession.selectOne(statementId, deptId, false);
        return adminDepartmentPo;
    }

    @Override
    public synchronized Integer getQBFWMaxId() {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.getQBFWMaxId";
        Integer maxId = sqlSession.selectOne(statementId, null, false);
        return maxId;
    }

    @Override
    public List<AdminDepartmentPo> findDeptListByBelongToSqL(String belongToSql) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findDeptListByBelongToSqL";
        List<AdminDepartmentPo> deptList = sqlSession.selectList(statementId, belongToSql, false);
        return deptList;
    }

    @Override
    public List<QBFWPo> showQBFWAuditList(QBFWAuditBo qbfwAuditBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.showQBFWAuditList";
        return sqlSession.selectList(statementId, qbfwAuditBo, false);
    }

    @Override
    public List<LCPo> getThreeLcByQBFWId(Integer qbfwId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.getThreeLcByQBFWId";
        return sqlSession.selectList(statementId, qbfwId, false);
    }


    @Override
    public long showQBFWAuditCount(QBFWAuditBo qbfwAuditBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.showQBFWAuditCount";
        return sqlSession.getCount(statementId, qbfwAuditBo);
    }

    @Override
    public List<QBFWPo> showHaveReadQBFWAuditList(QBFWAuditBo qbfwAuditBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.showHaveReadQBFWAuditList";
        return sqlSession.selectList(statementId, qbfwAuditBo, false);
    }

    @Override
    public long showHaveReadQBFWAuditCount(QBFWAuditBo qbfwAuditBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.showHaveReadQBFWAuditCount";
        return sqlSession.getCount(statementId, qbfwAuditBo);
    }

    @Override
    public List<QBFWPo> queryQBFWList(QBFWBo qbfwBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.queryQBFWList";
        List<QBFWPo> qbfwPoList = sqlSession.selectList(statementId, qbfwBo, false);
        return qbfwPoList;
    }

    @Override
    public Boolean delQBFWById(Integer qbfwId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.delQBFWById";
        return sqlSession.executeDelete(statementId, qbfwId);
    }

    @Override
    public long queryQBFWCount(QBFWBo qbfwBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.queryQBFWCount";
        return sqlSession.getCount(statementId, qbfwBo);
    }

    @Override
    public QBFWVo showSingleQBFW(Integer qbfwId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.showSingleQBFW";
        return sqlSession.selectOne(statementId, qbfwId, false);
    }

    @Override
    public Boolean updataQBFW(QBFWBo qbfwBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.updataQBFW";
        return sqlSession.executeUpdate(statementId,qbfwBo);
    }

    @Override
    public AdminDepartmentPo findDeptNameByDeptId(String deptId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findDeptNameByDeptId";
        return sqlSession.selectOne(statementId,deptId,false);
    }

    @Override
    public AdminPermissionGroupPo findQXZBbyQXZId(String qxzId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findQXZBbyQXZId";
        return sqlSession.selectOne(statementId,qxzId,false);
    }

    @Override
    public List<AdminDepartmentPo> findDeptsByLeader(String leaderId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findDeptsByLeader";
        return sqlSession.selectList(statementId,leaderId,false);
    }

    @Override
    public AdminDepartmentPo findIsQbDeptLeader(AdminDepartmentPo departmentPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findIsQbDeptLeader";
        return sqlSession.selectOne(statementId,departmentPo,false);
    }

    @Override
    public AdminPermissionGroupPo findIsPermissionGroupMember(String sql) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findIsPermissionGroupMember";
        return sqlSession.selectOne(statementId,sql,false);
    }

    @Override
    public Boolean updateQBFWNode(QBFWPo qbfwPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.updateQBFWNode";
        return sqlSession.executeUpdate(statementId,qbfwPo);
    }

    @Override
    public AdminDepartmentPo findDeptByDeptIdAndLeaderId(AdminDepartmentPo departmentPo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.IQBFWDao.findDeptByDeptIdAndLeaderId";
        return sqlSession.selectOne(statementId, departmentPo, false);
    }
}
